#include "contentmodel.h"

ContentModel::ContentModel(QObject *parent)
    :QAbstractListModel(parent)
{
    m_contentItems.clear();
}



int ContentModel::rowCount(const QModelIndex & parent) const {
    Q_UNUSED(parent);
    return m_contentItems.count();
}

QVariant ContentModel::data(const QModelIndex & index, int role) const {
    if (index.row() < 0 || index.row() >= m_contentItems.count())
        return QVariant();

    const TextData textData = m_contentItems[index.row()];

    if (role == ContentRole)
        return textData.data();
    else if (role == TypeRole) {
        return textData.type();
    }

    return QVariant();
}

QHash<int, QByteArray> ContentModel::roleNames() const {
    QHash<int, QByteArray> roles;
    roles[ContentRole] = "contentRow";
    roles[TypeRole] = "type";
    return roles;
}

void ContentModel::setContentArticle(const QList<TextData>& _contentItems)
{
    beginResetModel();
    m_contentItems = _contentItems;
    endResetModel();
}
